package ace.module.account.core.impl.service.callback.auth.handler.impl.password;

import ace.module.account.api.model.auth.input.params.AuthenticationParamsPassword;
import ace.module.account.core.impl.service.callback.auth.enums.AuthenticationTypeCallbackEnum;
import ace.module.account.core.impl.service.callback.auth.handler.impl.AbstractOauth2AuthenticationCallbackHandler;
import ace.module.account.core.impl.service.callback.auth.model.bo.Oauth2AuthenticationCallbackContext;
import ace.module.oauth2.server.api.model.input.params.Oauth2AceAuthParamsUsername;
import org.springframework.stereotype.Component;

/**
 * 账号与密码认证，账号支持类型：用户名、电子邮件、手机号码.
 *
 * @author caspar
 * @date 2023/3/16 9:49
 */
@Component
public class PasswordOauth2AuthenticationCallbackHandler
    extends AbstractOauth2AuthenticationCallbackHandler<Oauth2AceAuthParamsUsername, AuthenticationParamsPassword> {

  public PasswordOauth2AuthenticationCallbackHandler() {
    super(AuthenticationTypeCallbackEnum.ALL_PASSPORT_PASSWORD);
  }

  @Override
  protected AuthenticationParamsPassword convertCallbackParamsToAuthenticationParams(Oauth2AuthenticationCallbackContext context, String oauth2AceAuthParamsMapString,
      Oauth2AceAuthParamsUsername oauth2AceAuthParamsUsername) {
    return AuthenticationParamsPassword.builder()
        .passport(oauth2AceAuthParamsUsername.getUsername())
        .password(oauth2AceAuthParamsUsername.getPassword())
        .captchaItemId(oauth2AceAuthParamsUsername.getCaptchaItemId())
        .code(oauth2AceAuthParamsUsername.getCode())
        .build();
  }
}
